package src.tp1;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;

public class Tp1Activity extends Activity {

	private EditText locationTextEdit = null;
	private Button locateBtn = null;
	private String location= null;


	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        this.locationTextEdit = (EditText) findViewById(R.id.locationInput);
        this.locateBtn = (Button) findViewById(R.id.locateBtn);
        
        this.location = "";
        
        Tp1Activity.runFadeOutAnimationOn(this, findViewById(R.id.imagen));
    }
	
	public void findLocation(View target){
		this.location = this.locationTextEdit.getText().toString();

		Intent locateAct = new Intent(target.getContext(), LocateActivity.class);
		locateAct.putExtra("location", this.location);
		
		startActivity(locateAct);
	}
	
	public static Animation runFadeOutAnimationOn(Activity ctx, View target) {
		  Animation animation = AnimationUtils.loadAnimation(ctx, R.anim.slide_right);
		  target.startAnimation(animation);
		  return animation;
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu){
	   MenuInflater inflater=getMenuInflater();
	   inflater.inflate(R.menu.menu, menu);
	   return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item){
	  AlertDialog.Builder builder = new AlertDialog.Builder(this);	
	    switch(item.getItemId()){
	    		case R.id.exit:
		    		builder.setMessage("Are you sure you want to wxit?");
		        	builder.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
		        		public void onClick(DialogInterface dialog, int id){
		        			Tp1Activity.this.finish();
		        		}
		        	});
		        	builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
		        		public void onClick(DialogInterface dialog, int id){
		        			dialog.cancel();
		        		}
		        	});
		        	builder.create();
		        	builder.show();
		    		return true;
		    	case R.id.about:
		    		builder.setMessage("Nosotros somos el Grupo X del curso UADE Android 2011.");
		    		builder.setTitle("About us");
		    		builder.setIcon(R.drawable.icon);
		        	builder.setNeutralButton("Cerrar", new DialogInterface.OnClickListener(){
		        		public void onClick(DialogInterface dialog, int id){
		        			dialog.cancel();
		        		}
		        	});
		        	builder.create();
		        	builder.show();
		    		return true;
		    	default:
		    		return super.onOptionsItemSelected(item);
	    	}
	    }
	

}